﻿@using Abp.Application.Services.Dto;
@using FwProject.Restaurant
@using FwProject.Restaurant.Dto
@using FwProject.Authorization
@using X.PagedList
@model IPagedList<LoadCarOutputDto>
@{
    ViewBag.Title = "装车单";
}
@section styles{
    <link href="~/Theme/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="~/Theme/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <style type="text/css">
        .input-group[class*=col-] {
            padding: 0 15px;
        }

        .fl {
            float: left;
        }
    </style>
}
<div class="row wrapper wrapper-content animated fadeInRight">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>@ViewBag.Title</h5>
                <div class="ibox-tools">
                    @if (IsGranted(PermissionNames.Distribution_Operation_LoadingEntry))
                    {
                        <a class="btn btn-primary btn-xs" href="javascript:top.window.openTab(1080,'装车录入','@Url.Action("CreateLoadCar")')">装车录入</a>
                    }
                    @if (IsGranted(PermissionNames.Distribution_Operation_Excel))
                    {
                        <a class="btn btn-primary btn-xs" href="javascript:Export()">Excel导出</a>
                    }

                </div>
            </div>
            <div class="ibox-content">
                <div class="row m-b-sm m-t-sm">
                    <form class="form-horizontal" id="form" asp-controller="Distribution" asp-action="LoadingInvoice" data-ajax="true" data-ajax-update="#data_list" data-ajax-method="Get" data-ajax-mode="replace" data-ajax-begin="AjaxBegin" data-ajax-success="AjaxSuccessCallback">
                        <input type="hidden" id="size" name="size" value="0" />
                        <div class="row m-b-sm">
                            <div class="col-lg-2 col-md-2">
                                <label class="control-label col-md-5 col-lg-5">状态：</label>
                                <div class="fl input-group">
                                    <enums asp-enum="typeof(FwProject.Core.Restaurant.ExamineStatus)" asp-isdefault="true" asp-name="ExamineStatus" asp-id="ExamineStatus" class="form-control"></enums>
                                </div>
                            </div>
                            <div class="col-md-2 col-lg-2">
                                <label class="control-label col-md-5 col-lg-5">司机：</label>
                                <div class="input-group">
                                    <input type="hidden" name="DriverId" id="DriverId" />
                                    <input type="text" id="dropdown-driverid" class="form-control" onblur="blurEmpty()" placeholder="全部">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown" style="line-height:1.455;padding:6px 12px;">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu" style="z-index: 9999;"></ul>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-2 col-md-2">
                                <label class="fl control-label">车牌号：</label>
                                <div class="input-group">
                                    <input type="text" name="PlatesNumber" id="PlatesNumber" placeholder="车牌号" class="input-sm form-control">
                                    @*<span class="input-group-btn">
                        <button type="submit" class="btn btn-sm btn-primary"> 搜索</button>
                    </span>*@
                                </div>
                            </div>
                            <div class="col-lg-5 col-md-5">
                                <label class="fl control-label">装车日期：</label>
                                <div class="col-md-3 col-lg-2">
                                    <select id="data_select" class="input-s form-control"></select>
                                </div>
                                <div class="input-daterange input-group" id="datepicker">
                                    <input type="text" name="BeginLimit" id="beginTime" placeholder="起始时间" class="input-sm form-control" autocomplete="off">
                                    <span class="input-group-addon">至</span>
                                    <input type="text" name="EndLimit" id="endTime" placeholder="结束时间" class="input-sm form-control" autocomplete="off" />
                                </div>
                            </div>
                            <div class="col-lg-1 col-md-1">
                                <div class="input-group" style="margin-right:20px">
                                    <button type="submit" class="btn btn-sm btn-success">搜索</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div id="data_list">
                    @*@{Html.RenderPartial("LoadingInvoicePartial", Model);}*@
                </div>
            </div>
        </div>
    </div>
</div>
<div id="modal_ajax" class="modal inmodal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
</div>
<div id="modal_del" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated fadeIn">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                <h4 class="modal-title">删除</h4>
            </div>
            <form action="" method="post" novalidate="novalidate" data-ajax="true" data-ajax-success="DeletAjaxCallback" data-ajax-failure="FailureAjaxCallback" data-ajax-method="Post" role="form">
                @Html.AntiForgeryToken()
                <div class="modal-body">
                    <p>确定要删除？</p>
                    @*<input type="hidden" name="id" value="" />*@
                </div>
                <div class="modal-footer">
                    <button type="reset" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button id="btn_del_sure" type="submit" class="btn btn-danger" data-loading-text="执行中...">确定</button>
                </div>
            </form>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
@section scripts{
    <script src="~/Theme/js/content.min.js?v=1.0.0"></script>
    <script src="~/Theme/js/plugins/iCheck/icheck.min.js"></script>
    <script src="~/Theme/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="~/Theme/js/plugins/suggest/bootstrap-suggest2014.js"></script>
    <script src="~/js/DateComm.js"></script>
    <script src="~/js/PrintUtil.js"></script>
    <script type="text/javascript">
        function Print() {
            printGirdObj({
                containerId: 'table_print',//包含表格容器のID
                title: '装车单',
                showRowNum: false,  //表格中rownumbers: true时为true
                showOrder: false,//是否显示序号，rownumbers: true时有效，默认false
                printInit: { //打印初始化设置参数
                    portrait: false //true纵向,false横向
                }
            });
        }

        function Export() {

            var ExamineStatus = $('#ExamineStatus').val();
            var DriverId = $('#DriverId').val();
            var PlatesNumber = $('#PlatesNumber').val();
            var BeginLimit = $('#beginTime').val();
            var EndLimit = $('#endTime').val();

            window.location.href = "/Distribution/ExportLoadingInvoice?ExamineStatus=" + ExamineStatus + "&&DriverId=" + DriverId + "&&PlatesNumber=" + PlatesNumber + "&&BeginLimit=" + BeginLimit + "&&EndLimit=" + EndLimit;
        }

        new DateContUtil({//【下拉日期】
            selectId: "data_select",//下拉框のID
            startDate: 'beginTime',//开始日期(不填默认search_startDateBase)
            endDate: 'endTime',//结束日期(不填默认search_endDateBase)
            defaultValue: '4',//本月
            selectedFun: function () {//选中后触发の方法
                $(".form-horizontal").submit();
            }
        });


        $('#beginTime').datepicker({
            todayBtn: "linked",
            autoclose: true,
            todayHighlight: true

        }).on('changeDate', function (e) {
            var startTime = e.date;
            $('#endTime').datepicker('setStartDate', startTime);
        });
        //结束时间：
        $('#endTime').datepicker({
            todayBtn: "linked",
            autoclose: true,
            todayHighlight: true

        }).on('changeDate', function (e) {
            var endTime = e.date;
            $('#beginTime').datepicker('setEndDate', endTime);
        });

        //layer.msg("test",{time:2000});
        $(document).ready(function () {
            //绑定司机
            $.getJSON("/Users/GetSuggestData?type=司机类型").done(function (data) {
                CommonAjaxCallback(data, function () {
                    bindSuggest(data.result);
                }, null);
            }).fail(function () {
                layer.msg('连接超时，获取司机信息失败！', {
                    icon: 2,
                    time: 2000
                });
            });


            $("body").on("click", ".table>tbody>tr td.collapsed i", function (e) {
                e.preventDefault();
                if ($(this).hasClass("fa-plus-square-o")) {
                    $(this).removeClass("fa-plus-square-o").addClass("fa-minus-square-o").parent().parent().next(".tb-child").removeClass("hidden");
                    var id = $(this).data("id");
                    var tb = $(this).removeClass("fa-plus-square-o").addClass("fa-minus-square-o").parent().parent().next(".tb-child").find(".tb_tbody");
                    tb.empty();
                    $.getJSON("/Distribution/GetLoadingCarData?id=" + id).done(function (data) {
                        if (data.success) {
                            if (data.result.length > 0) {
                                for (var i = 0; i < data.result.length; i++) {
                                    var tr = $('<tr>');
                                    var unit = data.result[i].typeNumberInfoModel.unit;
                                    if (unit == "0") {
                                        unit = "个";
                                    }
                                    else if (unit == "1") {
                                        unit = "箱";
                                    }
                                    else if (unit == "2") {
                                        unit = "件";
                                    }
                                    else if (unit == "3") {
                                        unit = "套";
                                    }
                                    tr.append('<td>' + data.result[i].typeNumberInfoModel.name + '</td>').append('<td>' + data.result[i].countproduct + '</td>').append('<td>' + unit + '</td>');
                                    tb.append(tr);
                                }
                            }

                        }
                    })
                }
                else {
                    $(this).removeClass("fa-minus-square-o").addClass("fa-plus-square-o").parent().parent().next(".tb-child").addClass("hidden");
                }
            });


            $('#modal_ajax').on('show.bs.modal', function (e) {
                $(this).addClass('loading');
                var $button = $(e.relatedTarget);
                var url = $button.data('url');
                if (!!url) {
                    url = url + ((url.indexOf("?") > -1) ? "&r=" : "?r=") + Math.random();
                    $(this).load(url, function () {
                        $.validator.unobtrusive.parse(this); //$("#form_model_create").validate();
                        $("input[name='Member.Birthday']").datepicker({ todayBtn: "linked", keyboardNavigation: !1, forceParse: !1, calendarWeeks: !0, autoclose: !0 });
                        $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", });
                        $(this).removeClass('loading');
                    });
                }
            });
            $('#modal_ajax').on('hidden.bs.modal', function (e) {
                $(this).empty();
            });

            $('#modal_del,#modal_password_reset').on('show.bs.modal', function (e) {
                var $button = $(e.relatedTarget);
                var url = $button.data('url');
                if (!!url)
                    url = url + ((url.indexOf("?") > -1) ? "&r=" : "?r=") + Math.random();
                $(this).find("form").attr("action", url);
            });
            $('#modal_del,#modal_password_reset').on('hidden.bs.modal', function (e) {
                $(this).find("form").attr("action", "");
            });

            $('#form').submit();
        });

        function bindSuggest(data) {
            if ($("#dropdown-driverid") != undefined) {
                $role = $("#dropdown-driverid").bsSuggest({
                    effectiveFields: ["name"],
                    effectiveFieldsAlias: { "name": "姓名" },
                    searchFields: ["name"],
                    clearable: true,
                    getDataMethod: "data",
                    //url: "/Users/GetSuggestData?type=司机类型&keyword=",
                    data: { value: data },
                    idField: "id",
                    keyField: "name",
                }).on('onDataRequestSuccess', function (e, result) {
                    console.log('onDataRequestSuccess: ', result);
                }).on('onSetSelectValue', function (e, keyword, data) {
                    $("#DriverId").val(data.id);
                    console.log('onSetSelectValue: ', keyword, data);
                }).on('onUnsetSelectValue', function () {
                    console.log('onUnsetSelectValue');
                });
            }
        }

        function ReloadAjaxCallbackgoback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                $('#modal_ajax').modal("hide");
                window.location.reload();
            }, successInfo);
        }

        function DeletAjaxCallback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                $("#modal_del").modal("hide");
                $($button).parent().parent().remove();
                window.location.reload();
            }, successInfo);
        }

        function blurEmpty() {
            var cityObj = $("#dropdown-driverid");
            var DriverId = $("#DriverId");
            if (cityObj.val() == "") {
                DriverId.attr("value", "");
            }
        }

        $("#data_list").on("change", "#pageSize", function () {
            var size = $("option:selected", this).val();
            $("#size").val(size);
            var pageurl = $("#pageurl").val();
            $("#form").submit();
        });
    </script>
}
